/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.BrewView;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "BrewLab")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "BrewLab.findAll", query = "SELECT b FROM BrewLab b"),
    @NamedQuery(name = "BrewLab.getAllComplete", query = "SELECT b FROM BrewLab b WHERE b.blComplete = 'false'")})
public class BrewLab implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "BrewLabID")
    private Integer blid;
    @Size(min = 0, max = 250)
    @Column(name = "BrewLabDesc")
    private String bldesc;
    @JoinColumn(name = "BrewLabBrewID", referencedColumnName = "BID", nullable=true)
    @ManyToOne(optional = true)
    private BrewView brews;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BrewLabComplete")
    private boolean blComplete;
    @Size(min = 0, max = 500)
    @Column(name = "BrewLabNotes")
    private String blNotes;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTBrewLabToBrewLabDetails",
        joinColumns={ @JoinColumn(name="BrewLabID", referencedColumnName="BrewLabID")},
        inverseJoinColumns={ @JoinColumn(name="BrewLabDetailsID", referencedColumnName="BrewLabDetailsID", unique=true)}
    )
    private List<BrewLabDetails> brewLabDetailsCollection;

    public BrewLab() {
    }

    public BrewLab(Integer blid) {
        this.blid = blid;
    }

    public BrewLab(Integer blid, String bldesc, boolean blComplete, String blNotes) {
        this.blid = blid;
        this.bldesc = bldesc;
        this.blComplete = blComplete;
        this.blNotes = blNotes;
    }

    public Integer getBlid() {
        return blid;
    }

    public void setBlid(Integer blid) {
        this.blid = blid;
    }

    public String getBldesc() {
        return bldesc;
    }

    public void setBldesc(String bldesc) {
        this.bldesc = bldesc;
    }

    public BrewView getBrews() {
        return brews;
    }

    public void setBrews(BrewView brews) {
        this.brews = brews;
    }

    public boolean isBlComplete() {
        return blComplete;
    }

    public void setBlComplete(boolean blComplete) {
        this.blComplete = blComplete;
    }

    public String getBlNotes() {
        return blNotes;
    }

    public void setBlNotes(String blNotes) {
        this.blNotes = blNotes;
    }

    public List<BrewLabDetails> getBrewLabDetailsCollection() {
        return brewLabDetailsCollection;
    }

    public void setBrewLabDetailsCollection(List<BrewLabDetails> brewLabDetailsCollection) {
        this.brewLabDetailsCollection = brewLabDetailsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (blid != null ? blid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BrewLab)) {
            return false;
        }
        BrewLab other = (BrewLab) object;
        if ((this.blid == null && other.blid != null) || (this.blid != null && !this.blid.equals(other.blid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.BrewLab[ blid=" + blid + " ]";
    }
}
